
//303.区域和检索 - 数组不可变
class NumArray {
    vector<int> lsum;       //记录从左向右到每个位置的和
public:
    NumArray(vector<int>& nums) {
        int n = nums.size();
        lsum.resize(n+1);
        for(int i = 0;i < n ;i++)
            lsum[i+1] = lsum[i] + nums[i];      //记录前缀和
    }
    
    int sumRange(int left, int right) {
        return lsum[right+1] - lsum[left];
    }
};

/**
 * Your NumArray object will be instantiated and called as such:
 * NumArray* obj = new NumArray(nums);
 * int param_1 = obj->sumRange(left,right);
 */